home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / NEW_CLNT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  4.6 KB  |  184 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <FILESYS.H>
  9. #include <OSBIND.H>
  10. #include <MINTBIND.H>
  11. #include <stdio.h>
  12. #include <memory.h>
  13. #include "XA_DEFS.H"
  14. #include "XA_TYPES.H"
  15. #include "XA_GLOBL.H"
  16. #include "C_WINDOW.H"
  17. #include "SYSTEM.H"
  18. #include "RESOURCE.H"
  19. #include "events.h"
  20. #include "DESKTOP.H"
  21.  
  22. /*
  23.     Open the clients comms pipe in response to an XA_NEW_CLIENT message
  24. */
  25. unsigned long XA_new_client(short clnt_pid,AESPB *pb)
  26. {
  27.     char pipe_name[50];
  28.     char fmt[]="u:\\pipe\\XaClnt.%d\0";
  29.     short f;
  30.     XA_CLIENT *client=Pid2Client(clnt_pid);
  31.  
  32.     if (!client->clnt_pipe_rd)    /* If this occurs, then we've got a problem */
  33.     {
  34.         DIAGS(("New Client - Error: client pipe does not exist yet?\n"));
  35.         /* PANIC - opening a global handle won't help because global
  36.             handles can't be used in an Fselect mask... */
  37.         return XAC_BLOCK ;
  38.     }
  39.  
  40.     if (!client->clnt_pipe_wr)
  41.     {
  42.         sprintf(pipe_name,fmt,clnt_pid);                        /* Open the clients reply pipe for writing to */
  43.         client->clnt_pipe_wr=(int)Fopen(pipe_name,O_RDWR);        /* Kernals end of pipe*/
  44.         client_handle_mask|=1L<<(client->clnt_pipe_wr);
  45.     }
  46.     
  47.     client->std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  48.  
  49.     sprintf(client->name,"Foreign client ?");
  50.     sprintf(client->proc_name,"XACLIENT");
  51.  
  52.     for(f=0; ((client->cmd_name[f]!='\0')&&(client->cmd_name[f]!='.'))&&(f<8); f++)
  53.         client->proc_name[f]=client->cmd_name[f];
  54.     
  55.     for(; f<8; f++)
  56.         client->proc_name[f]=' ';
  57.  
  58.     client->proc_name[8]='\0';
  59.  
  60.     return XAC_DONE;    /* We now unblock the client, 'coz we've setup our end */
  61. }
  62.  
  63. /*
  64.     Close down the client reply pipe in response to an XA_CLIENT_EXIT message
  65.     - also does a tidy-up and delete's all the clients windows (in case some untidy programs
  66.       fail to close them for themselves).
  67.     - also disposes of any pending messages.
  68. */
  69. unsigned long XA_client_exit(short clnt_pid,AESPB *pb)
  70. {
  71.     XA_WINDOW *wl,*dwl;
  72.     XA_AESMSG_LIST *nm,*dnm;
  73.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  74.     XA_CLIENT *client=Pid2Client(clnt_pid);
  75.  
  76. #if 0
  77.     Fclose(client->clnt_pipe_wr);    /* Close the kernal end of client reply pipe */
  78.     client_handle_mask&=~(1L<<client->clnt_pipe_wr);
  79.  
  80.     client->clnt_pipe_wr=0;
  81. #endif
  82.  
  83. /* Go through and check that all windows belonging to this client are */
  84. /* closed and deleted (in case of sloppy programming). */
  85.     for(wl=window_list; wl;)
  86.     {
  87.         if ((wl->owner==clnt_pid)&&(wl!=root_window))
  88.         {
  89.             dwl=wl;
  90.  
  91.             /* No need to redraw anything if window is already closed... */
  92.             if (wl->is_open)
  93.             {
  94.  
  95.                 v_hide_c(V_handle);
  96.             
  97.                 display_windows_below(wl);                /* Redisplay any windows below the one we are closing */
  98.             
  99.                 v_show_c(V_handle, 1);
  100.             }
  101.             
  102.             wl=wl->next;
  103.             
  104.             if (window_list==dwl)                    /* Actually delete the window */
  105.                 window_list=dwl->next;
  106.  
  107.             if (dwl->prev) dwl->prev->next=dwl->next;
  108.             if (dwl->next) dwl->next->prev=dwl->prev;
  109.  
  110.             free(dwl);
  111.         }else{
  112.             wl=wl->next;
  113.         }
  114.     }
  115.  
  116. /* Dispose of any pending messages for the client */
  117.     for(nm=client->msg; nm;)
  118.     {
  119.         dnm=nm;
  120.         nm=nm->next;
  121.         free(dnm);
  122.     }
  123.     client->msg=NULL;
  124.  
  125. /* If the client forgot to remove it's menu bar, better do it now */
  126.     if (menu_bar->tree==client->std_menu)
  127.     {
  128.         menu_bar->tree=ResourceTree(system_resources,SYSTEM_MENU);
  129.         menu_bar->owner=AESpid;
  130.         v_hide_c(V_handle);
  131.         display_non_topped_window(root_window,NULL); 
  132.         v_show_c(V_handle,1);
  133.     }
  134.  
  135. /* Did the exiting app forget to remove a custom desktop? */
  136.     if ((desktop==client->desktop)&&(desktop!=ResourceTree(system_resources,DEF_DESKTOP)))
  137.     {
  138.         set_desktop(Pid2Client(menu_bar->owner)->desktop);
  139.  
  140.         v_hide_c(V_handle);
  141.         display_non_topped_window(root_window,NULL);
  142.         v_show_c(V_handle,1);
  143.     }
  144.  
  145. #if 0
  146. /* If the client forgot to free it's resources, we do it for them. */
  147.     if (client->std_resource)
  148.     {
  149.         FreeResources(client->std_resource);
  150.         clients->std_resource=NULL;
  151.     }
  152. #endif
  153.  
  154.     /* Free command tail and name *only if* they were malloced: */
  155.     if (client->cmd_tail != dummy_cmd_tail)
  156.         free(client->cmd_tail);
  157.     if (client->cmd_name != dummy_cmd_name)
  158.         free(client->cmd_name);
  159.  
  160.     client->std_resource=NULL;
  161.     client->cmd_tail=(char*)dummy_cmd_tail;
  162.     client->cmd_name=(char*)dummy_cmd_name;
  163.     client->zen=NULL;
  164.     client->desktop=NULL;
  165.     
  166.     if (update_lock==clnt_pid)                    /* unlock mouse & screen */
  167.     {
  168.         update_lock=FALSE;
  169.         update_cnt=0;
  170.     }
  171.  
  172.     if (mouse_lock==clnt_pid)
  173.     {
  174.         mouse_lock=FALSE;
  175.         mouse_cnt=0;
  176.     }
  177.  
  178. #if 0        /* Zombies are cleaned up by the child signal handler... */
  179.     Pwait3(1,NULL);
  180. #endif
  181.  
  182.     return XAC_DONE;    /* Closed down, let the client move on & exit */
  183. }
  184.